import 'package:get/get.dart';
import 'package:sinosheets/network/api.dart';
import 'package:sinosheets/utils/lottie_utils.dart';

class SearchProductLogic extends GetxController {
  String keyword = '';
  @override
  void onReady() {
    // TODO: implement onReady
    super.onReady();
    keyword = Get.arguments['keyword'] ?? '';
    LottieUtils.showToastLoading;
    getSearchProductList();
  }

  @override
  void onClose() {
    // TODO: implement onClose
    super.onClose();
  }

  /// 获取搜索商品列表
  List searchProductList = [];
  Future<void> getSearchProductList() async {
    Map<String, dynamic> params = {
      'q': keyword,
      'pageNum': 1,
      'pageSize': 20,
    };
    BaseResponse response = await ProductApi.getProductList(params);
    if (response.isSuccess) {
      searchProductList = response.list ?? [];
      update();
    }
    LottieUtils.hideToastLoading;
  }
}
